<?php

namespace app\serverfavorite\service\favorite;
use \app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-06-12 11:08:11
 * @Description: 收藏
 */

class Favorite extends ApiBase
{
	
    protected $favoriteLogic = 'app\serverfavorite\logic\Favorite';
	protected $favoriteCategoryLogic = '\app\serverfavorite\logic\FavoriteCategory';
    protected $favoriteValidate = 'app\serverfavorite\validate\Favorite';

    use \app\serversetting\traits\AddCheckAppId;
    /*添加一个收藏*/
    public function addFavorite(): array 
    {
    	$data = $this->haveIssetReceiveData(['app_id'=>0,'user_id'=>0,'cate_id'=>0,'obj_id'=>0,'snapshoot'=>'','user_info'=>'']);

    	$validate = validate($this->favoriteValidate);
        if(!$validate->scene('addFavorite')->check($data)){
            return verify_err(null, $validate->getError());
        }

        $checkAppId = $this->_addCheckAppId($data, logic($this->favoriteCategoryLogic), 'dbCateInfo', 'cate_id');
        if($checkAppId['status'] != SUCCESS_STATUS){
            return $checkAppId;
        }

        $favorite = $this->logic($this->favoriteLogic)->dbOneFavorite($data);
        if($favorite){
        	return verify_err(null, '您已经添加过了');
        }

    	return $this->logic($this->favoriteLogic)->addFavorite($data);
    }

    /*取消一个收藏*/
    public function cancelOne(): array 
    {
    	$data = $this->receiveData(['id'=>0, 'user_id'=>0]);
    	return $this->stepRun($data, 'cancelOne');
    }

    /*获取一个收藏详情*/
    public function favoriteInfo(): array 
    {
    	$data = $this->receiveData(['id'=>0, 'user_id'=>0]);
    	return $this->stepRun($data, 'favoriteInfo');
    }

    /*获取指定用户的收藏列表*/
    public function userFavoriteList(): array 
    {
    	$data = $this->issetReceiveData(['user_id'=>0,'page'=>1,'listRows'=>15,'cate_id'=>0,'field_name'=>'','field_value'=>'','app_id'=>0]);
    	return $this->stepRun($data, 'userFavoriteList');
    }

    /*后台管理员获取收藏列表*/
    public function favoriteList(): array 
    {
    	$data = $this->haveIssetReceiveData(['app_id'=>0,'user_id'=>0,'page'=>1,'listRows'=>15]);
    	return $this->stepRun($data, 'favoriteList');
    }

    
}






